package cn.ekuma.epos.analysis.singleproduct.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;

import cn.ekuma.epos.analysis.singleproduct.SingleProductAnalysis;

public class SingleProductAnalysisTableModel extends AbstractTableModel{
	List<SingleProductAnalysis> rows;
    ArrayList<String> transactionColumnName;
    
    public SingleProductAnalysisTableModel() {
        rows=new ArrayList();
        transactionColumnName=new ArrayList<String>();
    }

    public void resert( ArrayList<String> columns,List<SingleProductAnalysis> rows){
        transactionColumnName=columns;
        this.rows=rows;
        this.fireTableStructureChanged();
    }

    public int getRowCount() {
        return rows.size();
    }

    @Override
    public String getColumnName(int column) {
        if(column<COLUMNS_Pref.length)
            return COLUMNS_Pref[column];
        if(column<COLUMNS_Pref.length+transactionColumnName.size())
            return transactionColumnName.get(column-COLUMNS_Pref.length);
        return COLUMNS_After[column-COLUMNS_Pref.length-transactionColumnName.size()];
    }

    public int getColumnCount() {
        return COLUMNS_Pref.length+transactionColumnName.size()+COLUMNS_After.length;
    }

    public SingleProductAnalysis get(int index){
        return rows.get(index);
    }

    public static String[] COLUMNS_Pref=new String[]{
           AppLocal.getIntString("label.prodname")
    };
    
    public static String[] COLUMNS_After=new String[]{
 };

    public Object getValueAt(int rowIndex, int columnIndex) {
    	SingleProductAnalysis selected=rows.get(rowIndex); 
        if(columnIndex<COLUMNS_Pref.length)
        	 switch (columnIndex) {
             case 0:
                 return Formats.TIMESTAMP.formatValue(selected.getCurDate());
        	 }
        if(columnIndex<COLUMNS_Pref.length+transactionColumnName.size()){
        	int realColumnIndex=columnIndex-COLUMNS_Pref.length;
            return selected.getTransaxtion(transactionColumnName.get(realColumnIndex));
        }
        return null;
    }
    
}
